package com.gaohe.web.controller.dcp;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gaohe.common.annotation.Log;
import com.gaohe.common.core.controller.BaseController;
import com.gaohe.common.core.domain.AjaxResult;
import com.gaohe.common.core.page.TableDataInfo;
import com.gaohe.common.enums.BusinessType;
import com.gaohe.common.utils.poi.ExcelUtil;
import com.gaohe.dcp.domain.DcpResult;
import com.gaohe.dcp.service.IDcpResultService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * 评测结果Controller
 *
 * @author ruoyi
 * @date 2025-04-23
 */
@RestController
@RequestMapping("/dcp/result")
public class DcpResultController extends BaseController
{
    @Autowired
    private IDcpResultService dcpResultService;
    @Autowired
    private ObjectMapper jacksonObjectMapper;

    /**
     * 张文豪
     *
     * @param dcpResult
     * @return
     */
    @PostMapping("/addDcpResult")
    public AjaxResult addDcpResult(@RequestBody DcpResult dcpResult) throws JsonProcessingException {
        logger.error("dcpResult:{}",dcpResult);
        return toAjax(dcpResultService.insertDcpResult(dcpResult));
    }

    /**
     * 查询评测结果列表
     */
    @PreAuthorize("@ss.hasPermi('dcp:result:list')")
    @GetMapping("/list")
    public TableDataInfo list(DcpResult dcpResult)
    {
        startPage();
        List<DcpResult> list = dcpResultService.selectDcpResultList(dcpResult);
        return getDataTable(list);
    }

    /**
     * 导出评测结果列表
     */
    @PreAuthorize("@ss.hasPermi('dcp:result:export')")
    @Log(title = "评测结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DcpResult dcpResult)
    {
        List<DcpResult> list = dcpResultService.selectDcpResultList(dcpResult);
        ExcelUtil<DcpResult> util = new ExcelUtil<DcpResult>(DcpResult.class);
        util.exportExcel(response, list, "评测结果数据");
    }

    /**
     * 获取评测结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('dcp:result:query')")
    @GetMapping(value = "/{resultId}")
    public AjaxResult getInfo(@PathVariable("resultId") Long resultId)
    {
        return success(dcpResultService.selectDcpResultByResultId(resultId));
    }

    /**
     * 新增评测结果
     */
    @PreAuthorize("@ss.hasPermi('dcp:result:add')")
    @Log(title = "评测结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DcpResult dcpResult)
    {
        return toAjax(dcpResultService.insertDcpResult(dcpResult));
    }

    /**
     * 修改评测结果
     */
    @PreAuthorize("@ss.hasPermi('dcp:result:edit')")
    @Log(title = "评测结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DcpResult dcpResult)
    {
        return toAjax(dcpResultService.updateDcpResult(dcpResult));
    }

    /**
     * 删除评测结果
     */
    @PreAuthorize("@ss.hasPermi('dcp:result:remove')")
    @Log(title = "评测结果", businessType = BusinessType.DELETE)
	@DeleteMapping("/{resultIds}")
    public AjaxResult remove(@PathVariable Long[] resultIds)
    {
        return toAjax(dcpResultService.deleteDcpResultByResultIds(resultIds));
    }
}
